cmake_minimum_required(VERSION 3.16.3)

set(PROJECT_NAME gaze)

project(${PROJECT_NAME})

set(CMAKE_CXX_STANDARD 17)

add_library(${PROJECT_NAME}-lib
        src/common.hpp
        src/common.cpp
        src/AppComponent.hpp
        src/DatabaseComponent.hpp
        src/SwaggerComponent.hpp

        # handler
        src/handler/AuthHandler.hpp

        # interceptor
        src/interceptor/AuthInterceptor.hpp

        # Controller
        src/controller/IndexController.hpp
        src/controller/AuthController.hpp
        src/controller/UserController.hpp
        src/controller/CameraController.hpp

        # enum
        src/enum/Role.hpp

        # db model
        src/db/model/UserModel.hpp
        src/db/UserDb.hpp
        src/db/model/LoginLogModel.hpp
        src/db/LoginLogDb.hpp
        src/db/model/CameraModel.hpp
        src/db/CameraDb.hpp

        # dto
        src/dto/DTOs.hpp
        src/dto/SignInDto.hpp
        src/dto/AuthResponseDto.hpp
        src/dto/UserCreateDto.hpp
        src/dto/UserUpdateDetailsDto.hpp
        src/dto/UserUpdateStatusDto.hpp
        src/dto/UserUpdatePasswordDto.hpp
        src/dto/UserResponseDto.hpp
        src/dto/UserServiceGetAllUsersQueryDto.hpp
        src/dto/CameraCreateDto.hpp
        src/dto/CameraUpdateDetailsDto.hpp
        src/dto/CameraUpdateStatusDto.hpp
        src/dto/CameraResponseDto.hpp
        src/dto/CameraServiceGetAllCameraQueryDto.hpp

        # validate
        src/validate/UserCreateDtoValidate.hpp
        src/validate/UserUpdateDetailsDtoValidate.hpp
        src/validate/UserUpdateStatusDtoValidate.hpp
        src/validate/UserUpdatePasswordDtoValidate.hpp
        src/validate/CameraUpdateDetailsDtoValidate.hpp
        src/validate/CameraUpdateStatusDtoValidate.hpp

        # service
        src/service/UserService.hpp
        src/service/UserService.cpp
        src/service/AuthService.hpp
        src/service/AuthService.cpp
        src/ErrorHandler.hpp
        src/ErrorHandler.cpp
        src/service/LocalizationService.hpp
        src/service/LocalizationService.cpp
        src/service/CameraService.hpp
        src/service/CameraService.cpp
)

## link libs

find_package(oatpp CONFIG REQUIRED)
find_package(oatpp-swagger CONFIG REQUIRED)
find_package(oatpp-sqlite CONFIG REQUIRED)
find_package(stduuid CONFIG REQUIRED)
find_package(nlohmann_json CONFIG REQUIRED)
find_package(cryptopp CONFIG REQUIRED)

target_link_libraries(${PROJECT_NAME}-lib
        # Oat++
        PUBLIC oatpp::oatpp
        PUBLIC oatpp::oatpp-swagger
        PUBLIC oatpp::oatpp-sqlite
        PUBLIC oatpp::oatpp-test
        PUBLIC stduuid
        #  JSON
        PRIVATE nlohmann_json::nlohmann_json
        PRIVATE cryptopp::cryptopp
)

add_custom_command(TARGET ${PROJECT_NAME}-lib POST_BUILD
        COMMAND ${CMAKE_COMMAND} -E copy_directory
        "${CMAKE_SOURCE_DIR}/resources" "${CMAKE_BINARY_DIR}/resources")

target_include_directories(${PROJECT_NAME}-lib PUBLIC src)

add_definitions(
        ## SQLite database file
        -DDATABASE_FILE="${CMAKE_CURRENT_SOURCE_DIR}/db.sqlite"
        ## define path to swagger-ui static resources folder
        -DOATPP_SWAGGER_RES_PATH="${oatpp-swagger_INCLUDE_DIRS}/../bin/oatpp-swagger/res"
)

if (CMAKE_SYSTEM_NAME MATCHES Linux)
    find_package(Threads REQUIRED)
    target_link_libraries(${PROJECT_NAME}-lib INTERFACE Threads::Threads ${CMAKE_DL_LIBS})
endif ()

## add executables

add_executable(${PROJECT_NAME}-exe
        src/App.cpp
)
target_link_libraries(${PROJECT_NAME}-exe ${PROJECT_NAME}-lib)
add_dependencies(${PROJECT_NAME}-exe ${PROJECT_NAME}-lib)

add_executable(${PROJECT_NAME}-test
        test/Tests.cpp
        test/app/TestComponent.hpp
        test/app/IndexApiTestClient.hpp
        test/IndexControllerTest.hpp
        test/IndexControllerTest.cpp
)
target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME}-lib)
add_dependencies(${PROJECT_NAME}-test ${PROJECT_NAME}-lib)

set_target_properties(${PROJECT_NAME}-lib ${PROJECT_NAME}-exe ${PROJECT_NAME}-test PROPERTIES
        CXX_STANDARD 17
        CXX_EXTENSIONS OFF
        CXX_STANDARD_REQUIRED ON
)

enable_testing()
add_test(project-tests ${PROJECT_NAME}-test)
